<?php

declare(strict_types=1);

namespace app;

use app\common\model\activity\ActivityModel;
use app\common\model\order\OrderModel;
use app\common\model\user\UserActivityModel;
use app\common\model\user\UserAddressModel;
use think\facade\Cache;
use Workerman\Worker;
// use Workerman\Timer;


class Timer
{
	public function onWorkerStart()
	{
		
		

		$time_interval = 60;
		\Workerman\Timer::add($time_interval, function () {
			$orderList = OrderModel::where('pay_status', 0)->whereIn('status', 1)
				->field('id,create_time,type')->select()->toArray();
			foreach ($orderList as $item) {
				if (time() >= strtotime($item['create_time']) + 1740) {
					if ($item['type'] == 1) {
						OrderModel::where('id', $item['id'])->delete();
						UserActivityModel::where('order_id', $item['id'])->delete();
					} else {
						OrderModel::where('id', $item['id'])->update(['status' => 0]);
					}
				}
			}
			ActivityModel::where('status', 1)->where('start_time', '<=', time())->update(['status' => 2]);
			ActivityModel::where('status', 2)->where('end_time', '<=', time())->update(['status' => 3]);
		});
	}
}
